home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / BROWSERS / GLUESTIK.ZOO / transtub.c < prev   
Encoding:
C/C++ Source or Header  |  1996-08-31  |  6.8 KB  |  353 lines

  1. #include <stddef.h>
  2. #include <osbind.h>
  3. #include <mintbind.h>
  4. #include <string.h>
  5. #include "global.h"
  6. #include "pipe.h"
  7.  
  8.  
  9. /* error messages, cribbed directly out of STIK.ACC */
  10. char *errors[] = {
  11.   "No error",
  12.   "Output Buffer full",
  13.   "No data available",
  14.   "EOF from remote",
  15.   "RST received from remote",
  16.   "RST.  Other end sent unacceptable pkt",
  17.   "No memory available",
  18.   "Connection refused by remote",
  19.   "A SYN was received in the window",
  20.   "Bad connection handle used",
  21.   "Socket in LISTEN state, can't send",
  22.   "No free CCB's available",
  23.   "No connection matches this packet (TCP)",
  24.   "Failure to connect to remote port (TCP)",
  25.   "Invalid TCP_close() requested",
  26.   "User timout expired",
  27.   "Connection timed out",
  28.   "Domain query, Can't resolve",
  29.   "Bad format in domain name or dotted decimal",
  30.   "Modem is not connected",
  31.   "Hostname does not exist",
  32.   "Resolver reached work limit",
  33.   "No nameserver found",
  34.   "Bad format of DNS query",
  35.   "Destination unreachable",
  36.   "No Address records found for name"
  37. };
  38. char error_error[] = "Unrecognized error code";
  39.  
  40. Daemon_Op OP_;
  41. Daemon_Retval RET_;
  42.  
  43.  
  44. int init_stubs()
  45. {
  46.   return 1;
  47. }
  48.  
  49.  
  50. void send_op(Daemon_Op *op, Daemon_Retval *ret)
  51. {
  52.   PMSG pmsg;
  53.  
  54. #ifdef DEBUG
  55.   debug("s", "Grabbing daemon semaphore");
  56. #endif
  57.   Psemaphore(2, DMN_SEMAPHORE, -1L);
  58.   OP_ = *op;
  59.   pmsg.userlong1 = (long)&OP_;
  60.   pmsg.userlong2 = (long)&RET_;
  61. #ifdef DEBUG
  62.   debug("sd", "Sending op ", OP_.common.op);
  63. #endif
  64.   Pmsg(2, DMN_MBOX, &pmsg);
  65. #ifdef DEBUG
  66.   debug("sd", "Returned from op ", OP_.common.op);
  67. #endif
  68.   *ret = RET_;
  69.   Psemaphore(3, DMN_SEMAPHORE, 0L);
  70. #ifdef DEBUG
  71.   debug("s", "Releasing daemon semaphore");
  72. #endif
  73. }
  74.  
  75.  
  76. char* do_get_err_text(int16 err)
  77. {
  78.   char *s;
  79.  
  80. #ifdef DEBUG
  81.   debug("s", "in get_err_text()");
  82. #endif
  83.   /* GlueSTiK extension:  for MiNTnet errno values that don't neatly
  84.      correspond to STiK error codes, we return (-1000 - errno) and
  85.      translate it back here. */
  86.   if (err < 0)
  87.     err = -err;
  88.   if (err > 1000 && (s = strerror(err - 1000)))
  89.     return s;
  90.   if (err > E_LASTERROR)
  91.     return error_error;
  92.   return errors[err];
  93. }
  94.  
  95. /* Incompatibility:  Does nothing.  We can't really support this well,
  96.    since MiNTnet transparently supports multiple modems, as well as
  97.    non-modem methods of connections, such as local networks */
  98. int16 do_carrier_detect(void)
  99. {
  100. #ifdef DEBUG
  101.   debug("s", "in carrier_detect()");
  102. #endif
  103.   return 0;
  104. }
  105.  
  106. int16 do_TCP_open(uint32 hostaddr, int16 port, int16 tos, uint16 obsize)
  107. {
  108.   Daemon_Op OP;
  109.   Daemon_Retval RET;
  110.  
  111.   OP.P_TCP_open.op = OP_TCP_OPEN;
  112.   OP.P_TCP_open.hostaddr = hostaddr;
  113.   OP.P_TCP_open.port = port;
  114.   OP.P_TCP_open.tos = tos;
  115.   OP.P_TCP_open.obsize = obsize;
  116.   send_op(&OP, &RET);
  117.   return RET.ret_int16;
  118. }
  119.  
  120. int16 do_TCP_close(int16 fd, int16 timeout)
  121. {
  122.   Daemon_Op OP;
  123.   Daemon_Retval RET;
  124.  
  125.   OP.P_TCP_close.op = OP_TCP_CLOSE;
  126.   OP.P_TCP_close.fd = fd;
  127.   OP.P_TCP_close.timeout = timeout;
  128.   send_op(&OP, &RET);
  129.   return RET.ret_int16;
  130. }
  131.  
  132. int16 do_TCP_send(int16 fd, char* buf, int16 buflen)
  133. {
  134.   Daemon_Op OP;
  135.   Daemon_Retval RET;
  136.  
  137.   OP.P_TCP_send.op = OP_TCP_SEND;
  138.   OP.P_TCP_send.fd = fd;
  139.   OP.P_TCP_send.buf = buf;
  140.   OP.P_TCP_send.buflen = buflen;
  141.   send_op(&OP, &RET);
  142.   return RET.ret_int16;
  143. }
  144.  
  145. int16 do_TCP_wait_state(int16 fd, int16 state, int16 timeout)
  146. {
  147.   Daemon_Op OP;
  148.   Daemon_Retval RET;
  149.  
  150.   OP.P_TCP_wait_state.op = OP_TCP_WAIT_STATE;
  151.   OP.P_TCP_wait_state.fd = fd;
  152.   OP.P_TCP_wait_state.state = state;
  153.   OP.P_TCP_wait_state.timeout = timeout;
  154.   send_op(&OP, &RET);
  155.   return RET.ret_int16;
  156. }
  157.  
  158. /* Incompatibility:  Does nothing.  MiNTnet handles this internally. */
  159. int16 do_TCP_ack_wait(int16 fd, int16 timeout)
  160. {
  161. #ifdef DEBUG
  162.   debug("s", "in TCP_ack_wait()");
  163. #endif
  164.   return E_NORMAL;
  165. }
  166.  
  167. int16 do_UDP_open(uint32 hostaddr, int16 port)
  168. {
  169.   Daemon_Op OP;
  170.   Daemon_Retval RET;
  171.  
  172.   OP.P_UDP_open.op = OP_UDP_OPEN;
  173.   OP.P_UDP_open.hostaddr = hostaddr;
  174.   OP.P_UDP_open.port = port;
  175.   send_op(&OP, &RET);
  176.   return RET.ret_int16;
  177. }
  178.  
  179. int16 do_UDP_close(int16 fd)
  180. {
  181.   Daemon_Op OP;
  182.   Daemon_Retval RET;
  183.  
  184.   OP.P_UDP_close.op = OP_UDP_CLOSE;
  185.   OP.P_UDP_close.fd = fd;
  186.   send_op(&OP, &RET);
  187.   return RET.ret_int16;
  188. }
  189.  
  190. int16 do_UDP_send(int16 fd, char* buf, int16 buflen)
  191. {
  192.   Daemon_Op OP;
  193.   Daemon_Retval RET;
  194.  
  195.   OP.P_UDP_send.op = OP_UDP_SEND;
  196.   OP.P_UDP_send.fd = fd;
  197.   OP.P_UDP_send.buf = buf;
  198.   OP.P_UDP_send.buflen = buflen;
  199.   send_op(&OP, &RET);
  200.   return RET.ret_int16;
  201. }
  202.  
  203. /* Incompatibility:  Does nothing.  MiNTnet handles its own "kicking" */
  204. int16 do_CNkick(int16 fd)
  205. {
  206. #ifdef DEBUG
  207.   debug("s", "in CNkick()");
  208. #endif
  209.   return E_NORMAL;
  210. }
  211.  
  212. int16 do_CNbyte_count(int16 fd)
  213. {
  214.   Daemon_Op OP;
  215.   Daemon_Retval RET;
  216.  
  217.   OP.P_CNbyte_count.op = OP_CNBYTE_COUNT;
  218.   OP.P_CNbyte_count.fd = fd;
  219.   send_op(&OP, &RET);
  220.   return RET.ret_int16;
  221. }
  222.  
  223. int16 do_CNget_char(int16 fd)
  224. {
  225.   Daemon_Op OP;
  226.   Daemon_Retval RET;
  227.  
  228.   OP.P_CNget_char.op = OP_CNGET_CHAR;
  229.   OP.P_CNget_char.fd = fd;
  230.   send_op(&OP, &RET);
  231.   return RET.ret_int16;
  232. }
  233.  
  234. NDB* do_CNget_NDB(int16 fd)
  235. {
  236.   Daemon_Op OP;
  237.   Daemon_Retval RET;
  238.  
  239.   OP.P_CNget_NDB.op = OP_CNGET_NDB;
  240.   OP.P_CNget_NDB.fd = fd;
  241.   send_op(&OP, &RET);
  242.   return RET.ret_NDBptr;
  243. }
  244.  
  245. int16 do_CNget_block(int16 fd, char* buf, int16 len)
  246. {
  247.   Daemon_Op OP;
  248.   Daemon_Retval RET;
  249.  
  250.   OP.P_CNget_block.op = OP_CNGET_BLOCK;
  251.   OP.P_CNget_block.fd = fd;
  252.   OP.P_CNget_block.buf = buf;
  253.   OP.P_CNget_block.len = len;
  254.   send_op(&OP, &RET);
  255.   return RET.ret_int16;
  256. }
  257.  
  258. void do_housekeep(void)
  259. {
  260.   /* do nothing */
  261. }
  262.  
  263. int16 do_resolve(char *hostname, char **realname, uint32 *addrs, int16 naddrs)
  264. {
  265.   Daemon_Op OP;
  266.   Daemon_Retval RET;
  267.  
  268.   OP.P_resolve.op = OP_RESOLVE;
  269.   OP.P_resolve.hostname = hostname;
  270.   OP.P_resolve.realname = realname;
  271.   OP.P_resolve.addrs = addrs;
  272.   OP.P_resolve.naddrs = naddrs;
  273.   send_op(&OP, &RET);
  274.   return RET.ret_int16;
  275. }
  276.  
  277. void do_ser_disable(void)
  278. {
  279.   /* do nothing */
  280. }
  281.  
  282. void do_ser_enable(void)
  283. {
  284.   /* do nothing */
  285. }
  286.  
  287. CIB* do_CNgetinfo(int16 fd)
  288. {
  289.   Daemon_Op OP;
  290.   Daemon_Retval RET;
  291.  
  292.   OP.P_CNgetinfo.op = OP_CNGETINFO;
  293.   OP.P_CNgetinfo.fd = fd;
  294.   send_op(&OP, &RET);
  295.   return RET.ret_CIBptr;
  296. }
  297.  
  298. char* do_KRmalloc(int32 size)
  299. {
  300.   Daemon_Op OP;
  301.   Daemon_Retval RET;
  302.  
  303.   OP.P_KRmalloc.op = OP_KRMALLOC;
  304.   OP.P_KRmalloc.size = size;
  305.   send_op(&OP, &RET);
  306.   return RET.ret_charptr;
  307. }
  308.  
  309. void do_KRfree(void *mem)
  310. {
  311.   Daemon_Op OP;
  312.   Daemon_Retval RET;
  313.  
  314.   OP.P_KRfree.op = OP_KRFREE;
  315.   OP.P_KRfree.mem = mem;
  316.   send_op(&OP, &RET);
  317. }
  318.  
  319. int32 do_KRgetfree(int16 flag)
  320. {
  321.   Daemon_Op OP;
  322.   Daemon_Retval RET;
  323.  
  324.   OP.P_KRgetfree.op = OP_KRGETFREE;
  325.   OP.P_KRgetfree.flag = flag;
  326.   send_op(&OP, &RET);
  327.   return RET.ret_int32;
  328. }
  329.  
  330. char* do_KRrealloc(char *mem, int32 newsize)
  331. {
  332.   Daemon_Op OP;
  333.   Daemon_Retval RET;
  334.  
  335.   OP.P_KRrealloc.op = OP_KRREALLOC;
  336.   OP.P_KRrealloc.mem = mem;
  337.   OP.P_KRrealloc.newsize = newsize;
  338.   send_op(&OP, &RET);
  339.   return RET.ret_charptr;
  340. }
  341.  
  342.  
  343. char *do_getvstr(char *var)
  344. {
  345.   Daemon_Op OP;
  346.   Daemon_Retval RET;
  347.  
  348.   OP.P_getvstr.op = OP_GETVSTR;
  349.   OP.P_getvstr.var = var;
  350.   send_op(&OP, &RET);
  351.   return RET.ret_charptr;
  352. }
  353.